<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>文件管理</title>
    {include file="common/_require"}

    <script>
        var currentHeaderNavItem = 'File';
        var currentLeftNavItem = 'index-{$Request.param.type|default=1}';
    </script>
</head>

<body class="layui-layout-body">

    <div class="layui-layout layui-layout-admin">
        {include file="common/_header"}

        {include file="common/left_file"}

        <div class="layui-body">

            <div style="padding:15px">
                <div class="main-header">
                    <span class="layui-breadcrumb">
                        <a>首页</a>
                        <a><cite>文件管理</cite></a>
                    </span>
                </div>
                <div class="main-container">
                    <div>
                        <form action="" lay-filter="filter" class="layui-form layui-form-pane ">
                            <input type="hidden" name="type" value="{$Request.param.type|default=1}">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label">范围</label>
                                    <div class="layui-input-inline" style="width: 200px;">
                                        <select name="status" lay-verify="">
                                            <option value="">全部</option>
                                            <option value="0">未使用(仅供预览)</option>
                                            <option value="1">已使用</option>
                                            <option value="2">已删除</option>
                                            <option value="3">已清除</option>
                                        </select>
                                    </div>

                                </div>
                                <div class="layui-inline">
                                    <button class="layui-btn">查询</button>
                                </div>
                            </div>

                        </form>
                    </div>
                    <div style="overflow: auto;">
                        <table class="layui-table">

                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>预览</th>
                                    <th>文件信息</th>
                                    <th style="min-width: 200px;">状态时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {php}$empty = '<tr>
                                    <td colspan="10">暂无数据</td>
                                </tr>';{/php}
                                {volist name="list" id="vo" empty="$empty"}
                                <tr class="item" data-id="{$vo.id}">
                                    <td>{$vo.id}</td>
                                    <td>
                                        {switch $vo.mime_type}
                                        {case image/png|image/gif|image/jpeg }
                                        <a href="{$vo.src}" target="_blank"><img
                                                onerror="this.src = '/static/images/error.jpg'" src="{$vo.src}"
                                                alt=""></a>
                                        {/case}
                                        {default /}
                                        <a href="{$vo.src}" target="_blank" class="layui-btn layui-btn-sm">打开源文件</a>
                                        {/switch}
                                    </td>
                                    <td>
                                        <p>保存名称:{$vo->getData('save_name')}</p>
                                        <p>文件名:{$vo->getData('file_name')}</p>
                                        <p>文件类型: {$vo.mime_type}</p>
                                        <p>文件用途: <span style="color: red">{$vo.type_title}</span> </p>
                                        <p>文件大小: {$vo.file_size}</p>
                                        <p>文件指纹: {$vo.file_md5}</p>
                                    </td>
                                    <td>
                                        <p style="color: red">{$vo.status}</p>
                                        <p>上传时间:{$vo.create_time}</p>
                                        <p>使用时间:{$vo.used_time}</p>
                                        <p>删除时间:{$vo.delete_time}</p>
                                        <p>清除时间:{$vo.clear_time}</p>
                                    </td>
                                    <td>
                                        <div class="layui-btn-container">
                                            {if condition="empty($vo->getData('clear_time'))" }
                                            {if condition="!empty($vo->getData('used_time')) &&
                                            empty($vo->getData('delete_time'))" }
                                            <div class="layui-btn layui-btn-sm force-clear">强制清除文件</div>
                                            {else /}
                                            <div class="layui-btn layui-btn-sm clear">清除文件</div>
                                            {/if}
                                            {/if}
                                            {if condition="empty($vo->getData('clear_time'))" }
                                            <a class="layui-btn layui-btn-sm" href="{$vo.src}" target="_blank">下载</a>
                                            {/if}

                                        </div>
                                    </td>
                                </tr>
                                {/volist}

                            </tbody>
                        </table>
                        <div>
                            {$list|raw}
                        </div>
                    </div>
                </div>
            </div>
        </div>


        {include file="common/_footer"}

        <script>
            layui.use(['layer', 'form'], function () {

                var form = layui.form;

                form.val('filter', {
                    status: '{$Request.param.status}'
                })

                $('.clear').click(function () {
                    var item = this;
                    console.log($(item).parents('.item').data('id'));

                    layer.confirm('确定要清除吗?清除后不能恢复', function () {
                        $.get('{:url("File/clear")}', {
                            id: $(item).parents('.item').data('id')
                        }, function (result) {
                            if (result.code == 0) {
                                layer.msg('删除成功');
                                $(item).parents('td').children().remove()
                            } else {
                                layer.msg(result.msg)
                            }
                        })
                    })
                })
                $('.force-clear').click(function () {
                    var item = this;

                    layer.confirm('确定要强制清除吗?该文件有可能正在使用', function () {
                        $.get('{:url("File/clear")}', {
                            id: $(item).parents('.item').data('id')
                        }, function (result) {
                            if (result.code == 0) {
                                layer.msg('删除成功');
                                $(item).parents('td').children().remove()
                            } else {
                                layer.msg(result.msg)
                            }
                        })
                    })
                })
            })
        </script>
    </div>
</body>

</html>